﻿using MediatR;
using Microsoft.EntityFrameworkCore;
using Traceability.Commont.Domains.AnimalsDomainFiles;
using Traceability.Commont.DTOs.CommontFiles;
using Traceability.Commont.Infrastructures.Interfaces;

namespace U.Enterprise.Api.Applications.AdmissionRegistrationFile
{
    public class ApproachSelectApproachBatchHander : IRequestHandler<ApproachSelectApproachBatchCommand, Resqults>
    {
        private readonly IBateRepository<Approach> appro;

        public ApproachSelectApproachBatchHander(IBateRepository<Approach> appro)
        {
            this.appro = appro;
        }

        public async Task<Resqults> Handle(ApproachSelectApproachBatchCommand request, CancellationToken cancellationToken)
        {
            try
            {
                Resqults res=new Resqults() { Code=0};
                var info = await appro.GetAll().FirstOrDefaultAsync(x=>x.ApproachBatch==request.ApproachBatch);
                if (info != null)
                {
                    res.Code += 1;
                }
                return res;
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
